package com.sky.controller.admin;

import com.sky.dto.MerchantCategoryDTO;
import com.sky.entity.MerchantCategory;
import com.sky.result.Result;
import com.sky.service.MerchantCategoryService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import java.util.List;

/**
 * 商家分类管理控制器
 */
@RestController
@RequestMapping("/admin/merchant-category")
@Api(tags = "商家分类管理接口")
public class MerchantCategoryController {
    
    @Autowired
    private MerchantCategoryService merchantCategoryService;
    
    /**
     * 获取所有商家分类
     * @return 分类列表
     */
    @GetMapping("/list")
    @ApiOperation("获取所有商家分类")
    public Result<List<MerchantCategory>> getAllMerchantCategories() {
        List<MerchantCategory> categoryList = merchantCategoryService.getAllMerchantCategories();
        return Result.success(categoryList);
    }
    
    /**
     * 根据ID获取分类
     * @param id 分类ID
     * @return 分类对象
     */
    @GetMapping("/{id}")
    @ApiOperation("根据ID获取分类")
    public Result<MerchantCategory> getMerchantCategoryById(@PathVariable Integer id) {
        MerchantCategory category = merchantCategoryService.getMerchantCategoryById(id);
        return Result.success(category);
    }
    
    /**
     * 创建商家分类
     * @param merchantCategoryDTO 分类数据
     * @return 创建的分类对象
     */
    @PostMapping("/create")
    @ApiOperation("创建商家分类")
    public Result<MerchantCategory> createMerchantCategory(@RequestBody MerchantCategoryDTO merchantCategoryDTO) {
        MerchantCategory category = merchantCategoryService.createMerchantCategory(merchantCategoryDTO);
        return Result.success(category);
    }
    
    /**
     * 更新商家分类
     * @param id 分类ID
     * @param merchantCategoryDTO 分类数据
     * @return 更新后的分类对象
     */
    @PutMapping("/{id}")
    @ApiOperation("更新商家分类")
    public Result<MerchantCategory> updateMerchantCategory(@PathVariable Integer id, @RequestBody MerchantCategoryDTO merchantCategoryDTO) {
        MerchantCategory category = merchantCategoryService.updateMerchantCategory(id, merchantCategoryDTO);
        return Result.success(category);
    }
    
    /**
     * 删除商家分类
     * @param id 分类ID
     * @return 成功结果
     */
    @DeleteMapping("/{id}")
    @ApiOperation("删除商家分类")
    public Result<String> deleteMerchantCategory(@PathVariable Integer id) {
        merchantCategoryService.deleteMerchantCategory(id);
        return Result.success("分类删除成功");
    }
}